<script>
	/**
	 * vuex管理登陆状态，具体可以参考官方登陆模板示例
	 */
	import {
		mapState,
		mapMutations,
	} from 'vuex';
	import QQMapWX from "common/qqmap-wx-jssdk.min.js"
	
	export default {
		data() {
			return {
				amapPlugin: null,
				key: '88b5d9ae0cec3f6c102a0c7a1a616f80'
			}
		},
		methods: {
			...mapMutations(['login']),
			// 打开App没有网络提示
			isHaveNetwork() {
				uni.getNetworkType({
					success: (res) => {
						if (res.networkType == 'none') {
							uni.showModal({
								title: '没有网络',
								content: '是否重新连接？',
								success: (res) => {
									if (res.confirm) {
										this.isHaveNetwork()
									}
								}
							})
						}
					}
				})
			},
			//获取位置信息
			async getLocationInfo() {
				return new Promise((resolve) => {
					//位置信息默认数据
					let location = {
						longitude: 0,
						latitude: 0,
						province: "",
						city: "",
						area: "",
						street: "",
						address: "",
					};
					uni.getLocation({
						type: "gcj02",
						success(res) {
							location.longitude = res.longitude;
							location.latitude = res.latitude;
							// 腾讯地图Api
							const qqmapsdk = new QQMapWX({
								key: 'TDXBZ-ELKYX-OQJ4D-ZTJ4V-K7CR5-TLFN7' //这里填写自己申请的key
							});
							qqmapsdk.reverseGeocoder({
								location,
								success(response) {
									let info = response.result;
									console.log(info);
									location.province = info.address_component.province;
									location.city = info.address_component.city;
									location.area = info.address_component.district;
									location.street = info.address_component.street;
									location.address = info.address;
									resolve(location);
								},
							});
						},
						fail(err) {
							console.log(err)
							resolve(location);
						},
					});
				});
			}

		},
		//全局对象
		globalData: {
			//获取方式：getApp().globalData.qq
			qq: '联系方式:942879858',
			customBar: 45 // 获取设备顶部导航栏，状态栏高度
		},
		computed: {
			...mapState(['userInfo']),
		},
		onLaunch: function() {
			// ========== 初始化 ====================
			// #ifdef APP-PLUS
			plus.screen.lockOrientation('portrait-primary'); //竖屏正方向锁定
			// #endif
			var _self = this;
			// const location =  this.getLocationInfo();
			// console.log(this.position)
			// 获取设备顶部导航栏，状态栏高度
			uni.getSystemInfo({
				success: (e) => {
					// this.compareVersion(e.SDKVersion, '2.5.0')
					let statusBar = 0 //状态栏高度
					let customBar = 0 // 状态栏高度 + 导航栏高度  
					let navbar = 0 // 自定义标题与胶囊对齐高度


					// #ifdef MP
					statusBar = e.statusBarHeight
					customBar = e.statusBarHeight + 45
					if (e.platform === 'android') {
						this.$store.commit('SET_SYSTEM_IOSANDROID', false)
						customBar = e.statusBarHeight + 50
					}
					// #endif


					// #ifdef MP-WEIXIN



					statusBar = e.statusBarHeight
					const custom = wx.getMenuButtonBoundingClientRect()
					customBar = custom.bottom + custom.top - e.statusBarHeight

					navbar = (custom.top - e.statusBarHeight) * 2 + custom.height
					// #endif


					// #ifdef MP-ALIPAY
					statusBar = e.statusBarHeight
					customBar = e.statusBarHeight + e.titleBarHeight
					// #endif


					// #ifdef APP-PLUS
					console.log('app-plus', e)
					statusBar = e.statusBarHeight
					customBar = e.statusBarHeight + 45
					// #endif


					// #ifdef H5
					statusBar = 0
					customBar = e.statusBarHeight + 45
					// #endif

					_self.globalData.customBar = customBar;


				}
			})



			
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*
		全局公共样式和字体图标
	*/
	@import "@/uni_modules/uview-ui/index.scss";
	@import "common/utils.css";

	@import "common/event.css";
	@import "common/font.css";

	page {
		background: $page-color-base;
	}
	.password{
		position: absolute;
		right: 20rpx;
		top: 18rpx;
		font-size: 38rpx;
		color: #FD7783;
		z-index: 10;
	}
	.card{
		background-color: #fff;
		padding: 26rpx;
		margin: 26rpx 0;
		border-radius: 11rpx 11rpx 11rpx 11rpx;
	}
	.flex{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
</style>